#ifndef _STRAWGUI_LOCALIZATION_RESOURCE_H_
#define _STRAWGUI_LOCALIZATION_RESOURCE_H_

#include "sResource.h"
#include "sConfig.h"
#include "sNamedObjectContainer.h"
#include <set>

namespace sgui
{
    
namespace obs
{

	struct sAddLangEvent : sEvent
	{
		u32 m_newSize;

        const EEventId getID() const { return EVID_ADD_ITEM; }
		sAddLangEvent(const u32 newSize) : m_newSize(newSize) {}
	};

	struct sRemoveLangEvent : sEvent
	{
		u32 m_removeIdx;

        const EEventId getID() const { return EVID_REMOVE_ITEM; }
		sRemoveLangEvent(const u32 removeIdx) : m_removeIdx(removeIdx) {}
	};

};

namespace res
{

    class sLocalizationItem : public sResourceItem
#ifdef _EDITOR
        , public obs::sObserver
#endif
    {
    private:
        const u32&                  m_langsCount;
        std::vector<std::wstring>   m_items;
    public:
		void load(const db::Record &file);
		void save(db::Record &file);
        void clear();

        std::wstring* operator[](const u32 langId);

#ifdef _EDITOR
        bool OnEvent(const obs::sEvent& event);
#endif

        sLocalizationItem(sGUI& gui, const std::wstring& name, const u32& langs);
    };

	class sLocalizationResource : public sResource
	{
	public:
		static const std::wstring RESOURCE_NAME;
    private:
        CONTAINER_WRAPPER(sLocalizationItem)        m_strings;
        std::map<std::wstring, u32>                 m_langs;
        u32                                         m_langsCount;
	public:
		void load(const db::Record &file);
		void save(db::Record &file);
        void clear();
        const std::wstring getClass() const { return RESOURCE_NAME; };

        sLocalizationItem* operator[](const std::wstring name);

        CONTAINER_WRAPPER(sLocalizationItem)& getStrings();

        std::wstring* getString(const std::wstring& name, const u32 langId);
        std::wstring* getString(const std::wstring& name, const std::wstring& langName);

#ifdef _EDITOR
		void exportRTTI(rtti::sInfoList& list);

        const u32 addLang(const std::wstring& name);
        void removeLang(const std::wstring& name);

        sLocalizationItem& addString(const std::wstring& name);
        void removeString(const std::wstring& name);
#endif

		sLocalizationResource(sGUI& gui, const std::wstring& name);
        ~sLocalizationResource();
	};

};
};

#endif